<?php
require_once(CORE_DIR.'components/captcha/captcha.php');

class captchaComponent extends CreateCaptCha {

	function __construct()
	{
		parent::__construct();
	}

	public function captcha()
	{
		$this->char = md5(uniqid());
	    $this->char_length = '5';
	    $this->img_size = array('85','24');
	    $this->fg = array('0','0','0');
	    $this->bg = array('255','255', '255');
	    $this->font_size = '16';
	    $this->font_char_width = '15';
	    $this->img_type = 'png';
	    $creatWord = $this->generateRandomWord();
	    $createPrefix = mt_rand();
	    $createImage = $this->generateImage($createPrefix, $creatWord);
	    $imageURL = CORE_URL.'components/captcha/tmp/';
	    $imageSRC = $imageURL . $createImage;
	    $imageWidth = $this->img_size[0];
	    $imageHeight = $this->img_size[1];
	    ?>
	    <div class="formCaptcha">
	        <img src="<?php echo $imageSRC; ?>"
	         alt="captcha"
	         width="<?php echo $imageWidth; ?>"
	         height="<?php echo $imageHeight; ?>" />
	        <input id="captcha_prefix" name="captcha_prefix" type="hidden"
	         value="<?php echo $createPrefix; ?>" />
	    </div>
	    <?php
	}

	public function checkCaptcha($captcha_prefix,$captcha_code)
	{
		return $this->check($captcha_prefix,$captcha_code);
	}

	public function removeCaptcha($captcha_prefix)
	{
	    $this->remove($captcha_prefix);
	    $this->cleanup();
	}

}